from fastapi import APIRouter, Depends, HTTPException
from multimedia_tools.schemas import InputMessage, ReturnMessage

from multimedia_tools.services import (
    create_audio,
    create_pic,
    create_video,
    modify_pic,
    test,
)

router_pic = APIRouter(prefix="/pic", tags=["图像生成"])
router_video = APIRouter(prefix="/video", tags=["视频生成"])
router_audio = APIRouter(prefix="/audio", tags=["音频生成"])
router_modify = APIRouter(prefix="/modify", tags=["图像修改"])
router_test = APIRouter(prefix="/test", tags=["测试接口"])


@router_pic.post("/", response_model=ReturnMessage)
async def get_pic(input: InputMessage):
    return await create_pic(input)


@router_video.post("/")
async def get_video():
    return await create_video()


@router_audio.api_route("/", methods=["GET", "POST"])
async def get_audio():
    return await create_audio()


@router_modify.api_route("/", methods=["GET", "POST"])
async def get_modify():
    return await modify_pic()


def common_params(q: str | None = None):
    return {"q": q}


@router_test.get("/")
async def get_test(query_params: dict | None = Depends(common_params)):
    # return await test()
    # print("Received query parameters:", query_params)
    if query_params.get("q") is None:
        raise HTTPException(status_code=400, detail="Query parameter 'q' is required")

    return {"message": "测试接口", "query_params": query_params}
